package com.java.mvc.action;

import com.java.mvc.framework.annotation.MyAutowried;
import com.java.mvc.framework.annotation.MyController;
import com.java.mvc.framework.annotation.MyRequestMapping;
import com.java.mvc.framework.annotation.MyRequestParam;
import com.java.mvc.service.DemoService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@MyController
@MyRequestMapping
public class DemoAction {

    @MyAutowried
    private DemoService demoService;

    @MyRequestMapping("/query")
    public void query(HttpServletRequest request,
                      HttpServletResponse response,
                      @MyRequestParam("name") String name) {
        String result = demoService.get(name);
        try {
            response.getWriter().write(result);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
